package com.metadata_system.common.db.mapper;

import com.metadata_system.common.db.entity.MetadataView;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface MetadataViewMapper extends Mapper<MetadataView> {
    @Select("select last_insert_id()")
    int getLastInsertId();

    @Select("delete from md_metadata_view where metadata_id=#{id}")
    void deleteByMetadataId(@Param("id") Integer id);

    @Select("select id from md_metadata_view where metadata_id=#{id}")
    List<Integer> getIdsByMetadataId(@Param("id") Integer id);

    @Select("delete from md_metadata_view where metadata_view_id=#{id}")
    void deleteByViewId(@Param("id") Integer id);

    @Select("select metadata_id from md_metadata_view where id=#{viewId}")
    Integer getMetadataIdByViewId(@Param("viewId") Integer viewId);

    @Select("select id from md_metadata_view where metadata_id=#{metadataId} order by id asc limit 1")
    Integer getViewIdByMetadataId(@Param("metadataId") Integer metadataId);

}